<?php

//some code to connect to the dbase

$username="root";
$password="dwd4zx6p";
$database="docdiscuss";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM documents";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>

<html>
<head>
<title>DocDiscuss Upload Prototype</title>
</head>

<body>
	<h2>Upload a document</h2>
	<form enctype="multipart/form-data" method="post" action="upload.php">
	Document Name: <input type="text" size="40" name="docName"/>
	<br/><br/>
	Choose document: <input type="file" name="docFile"/>
	<br/><br/>
	<input type="submit" value="Upload document for annotation!"/>
	</form>
	<hr/>
	<h2>Your Documents (<?php echo $num;?> documents)</h2>
	<?php
		if($num > 0) {
		$i=0;
	?>
	<ul>
		<?php
			while($i < $num) {
				$id = mysql_result($result,$i,"id");
				$docName = mysql_result($result,$i,"name");
				$fileName = mysql_result($result,$i,"filename");
				$status = mysql_result($result,$i,"status");
				$printStatus = "Processing";
				if($status == 1) {
					$printStatus = "Completed";
				echo "<li><a href=annotate.php?id=" .$id . ">" . $docName . "</a>" . " (" . $printStatus . ")";
				} else {
				echo "<li>" . $docName . "" . " (" . $printStatus . ")";
}	
				$i++;
			}
		?>
	</ul>
	<?php
	}
	?>
</body>


</html>
